<!-- UserModel.php-->
<?php 
	//require 'common/ConnDB.php';
	//require 'common/config.php';
	require 'Model.php';
	class novelModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getnovelList(){
			$sql = 'select * from novels';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}

		function getnovelinfor($novelname){
			$sql = "select * from novels where novelname like '%".$novelname."%' limit 0,10 ";;
			$data = $this->conn->query($sql);
			return $data;
		}

		function getUserByID($id){
			$sql = "select * from novels where nid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatenovel($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
		  	$novel = array(
				'nid' =>$_POST['nid'],
				'novelname' => $_POST['novelname'],
				'tid' => $_POST['tid'],
				'pic' => $pic,
				'intro' => $_POST['intro'],
				'uploaddate' => $_POST['uploaddate'],
				);
		  	var_dump($novel);
			$sql="update novels set nid='$novel[nid]',novelname='$novel[novelname]',tid='$novel[tid]',pic='$novel[pic]',intro='$novel[intro]',uploaddate='$novel[uploaddate]' where nid=".$novel['nid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addnovel($data){
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
			$user = array(
				'nid' =>'',
				'novelname' => $data['novelname'],
				'tid' => $data['tid'],
				'pic' => $pic,
				'intro' => $data['intro'],
				'uploaddate' => $data['uploaddate'],
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
	
			$sql="insert into novels ({$keys}) VALUES ('{$values}')";
		
			$result = $this->conn->query($sql);
			return $result;
		}

		function Delnovel($id){
			$sql = "Delete from novels where nid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>